package com.example.campuslink.commen.adpter

import android.widget.RadioButton
import android.widget.TextView
import com.example.campuslink.BR
import com.example.campuslink.R
import com.example.campuslink.commen.core.CoreAdapter
import com.example.campuslink.commen.core.CoreViewHolder
import com.example.campuslink.databinding.AdapterTopicTabBinding
import com.example.campuslink.viewModel.MainFragmentViewModel

class TopicTabAdapter(vm: MainFragmentViewModel) :
    CoreAdapter<AdapterTopicTabBinding, MainFragmentViewModel, String>(
        BR.data,
        BR.viewModel,
        vm
    ) {
    override fun getItemLayoutId(viewType: Int): Int {
        return R.layout.adapter_topic_tab
    }

    override fun onBindViewHolder(holder: CoreViewHolder, position: Int) {
        super.onBindViewHolder(holder, position)
        holder.binding.root.findViewById<RadioButton>(R.id.rb_topic_tab_name).text =
            mListData[position]

        if (mViewModel?.topicTableIndex?.value == position) {
            holder.binding.root.findViewById<RadioButton>(R.id.rb_topic_tab_name).isChecked = true
        } else {
            holder.binding.root.findViewById<RadioButton>(R.id.rb_topic_tab_name).isChecked = false
        }
        holder.binding.root.setOnClickListener {
            mViewModel?.setTopicTableIndex(position)
            mViewModel?.setTopicTableType(mListData[position])
            mViewModel?.getInvitation(mListData[position])
            notifyDataSetChanged()
        }
    }
}